
package com.xnp.reader.service;

import com.xnp.reader.BuildConfig;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;

public class ReadingService extends Service {
    private static final String TAG = "ReadingService";
    private static final boolean DBG = BuildConfig.DEBUG;

    public static final String SEND_ACTION = "ReadingService.send";
    public static final String SEND_COUNT = "ReadingService.count";
    private boolean disableThread = false;
    private int count;

    @Override
    public IBinder onBind(Intent arg0) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        new Thread(new Runnable() {

            @Override
            public void run() {
                while (!disableThread) {
                    try {
                        Thread.sleep(10000);
                    } catch (InterruptedException e) {
                    }
                    count++;
                    if(count%10 == 0){
                        Intent it = new Intent(SEND_ACTION);
                        it.putExtra(SEND_COUNT, count);
                        sendBroadcast(it);
                    }
                    if (DBG)
                        Log.v(" CountService ", " Count is " + count);
                }
            }
        }).start();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.disableThread = true;
        if (DBG)
            Log.v(" read Service ", " on destroy ");
    }

}
